// pages/Cprofile/Cprofile.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

    prenext: "../Watchus/Watchus",
    preprve: "../Address/Address",
    page: 10,
    cptitle: {
      
      zw: "商务合作",
      yw: "Business Cooperation"
    },
    accounts: ["商业合作", "职位申请"],
    accountIndex: 0,
    isshangye: true,
    industryIndex: 0,
    industrys: ["餐饮", "IT"],
    industry: "请选择您所在的行业",
    jobIndex: 0,
    jobs: ["UI", "前端"],
    job: "请选择职位",
    startpoint: [],
    movePoint: [],
    opacitycontainer: {},
    name: "",
    mobile: "",
    email: "",
    content: "",
    xxgg1:{
        xx: "",
        gg: ""
      },
    xxgg2:{
        xx: "",
        gg: ""
      },
  
  },
  bindKeyname: function (e) {
    this.setData({
      name: e.detail.value
    })
  },
  bindKeymobile: function (e) {
    var myreg = new RegExp('^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\\d{8})$', 'g');
    if (!myreg.exec(e.detail.value)){
      this.setData({
        xxgg1:{
            xx: true,
            gg:false
         }

      })
    }
    else{
      this.setData({
        xxgg1: {
          xx: false,
          gg: true
        }

      })
    }
    this.setData({
      mobile: e.detail.value
    })
  },
  bindKeyemail: function (e) {
    var myreg = new RegExp('^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$', 'g');
    if (!myreg.exec(e.detail.value)) {
      this.setData({
        xxgg2: {
          xx: true,
          gg: false
        }

      })
    }
    else {
      this.setData({
        xxgg2: {
          xx: false,
          gg: true
        }

      })
    }
    this.setData({
      email: e.detail.value
    })
  },
  bindKeycontent: function (e) {
    this.setData({
      content: e.detail.value
    })
  },
  linkMe:function(){
    var that = this;
    if (that.data.name == "") {
      wx.showToast({
        title: '企业名或姓名不能为空',
        icon: "none"
      })
      return;
    }
    if (that.data.mobile == "") {
      wx.showToast({
        title: '手机号码不能为空',
        icon: "none"
      })
      return;
    }
    if (that.data.email == "") {
      wx.showToast({
        title: '邮箱不能为空',
        icon: "none"
      })
      return;
    }
    // if (that.data.content == "") {
    //   wx.showToast({
    //     title: '企业名或姓名不能为空',
    //     icon: "none"
    //   })
    // }
    if(that.data.xxgg1.gg==true&&that.data.xxgg2.gg==true){

      wx.request({
        url: 'http://www.amutong.cn/app/linkMe.json',
        data: {
          name: that.data.name,
          mobile: that.data.mobile,
          email: that.data.email,
          content: that.data.content,
          resourceFrom: "XCX"
        },
        method: "GET",
        dataType: "json",
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: function (res) {
          wx.showToast({
            title: res.data.message,
            icon: "none"
          });
          console.log(res.data);
          if (res.data.code == 1) {
            console.log(11)
            that.setData({
              name: "",
              mobile: "",
              email: "",
              content: "",
            })
          }
        }
      })
    }
    if (that.data.xxgg1.gg == false ||that.data.xxgg2.gg == false){
      wx.showToast({
        title: '请输入正确的手机号码或邮箱',
        icon:"none"
      })
    }
  },
  touchstartfun: function (e) {
    var that = this;
    //开始触摸，获取触摸坐标
    that.setData({
      startpoint: [e.touches[0].pageX, e.touches[0].pageY]
    });
  },
  touchmovefun: function (e) {
    //触摸移动中，获取触摸坐标
    var that = this;
    that.setData({
      movePoint: [e.touches[0].pageX, e.touches[0].pageY]
    });
    var startY = this.data.startpoint[1];
    var moveY = this.data.movePoint[1];
  
  },
  touchendfun: function (e) {
    var that = this;
    var startY = this.data.startpoint[1];
    var moveY = this.data.movePoint[1];
    if (startY - moveY > 80) {
      wx.reLaunch({
        url: that.data.prenext
      })
    }
    else if (startY - moveY<-80){
      wx.reLaunch({
        url: that.data.preprve
      })
    }
  },
  bindAccountChange: function (e) {

    this.setData({
      accountIndex: e.detail.value
    })
    if (this.data.accountIndex == 0) {
      this.setData({
        isshangye: true
      })
    }
    if (this.data.accountIndex == 1) {
      this.setData({
        isshangye: false
      })
    }
  },
  bindindustryChange: function (e) {
    this.setData({
      industryIndex: e.detail.value
    })
    this.setData({
      industry: this.data.industrys[this.data.industryIndex]
    })
  },
  bindjobChange: function (e) {
    this.setData({
      jobIndex: e.detail.value
    })
    this.setData({
      job: this.data.jobs[this.data.jobIndex]
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (this.data.accountIndex == 0) {
      this.setData({
        isshangye: true
      })
    }
    if (this.data.accountIndex == 1) {
      this.setData({
        isshangye: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      bg1leftstyle: "bg1leftstyle",
      bg2leftstyle: "bg2leftstyle",
      bgotstyle: "bgotstyle",
      bgotimgstyle: "bgotimgstyle",
      line2style: "line2style",
      styleArr: ["itemstyle", "boimgimagestyle"],
      bottomdata: {
        page: 8,
        styleArr: ["bottomstyleArr1", "bottomstyleArr2", "viewstyleArr"]
      },
      cptitle: {
        cptitlestyle: "cptitlestyle",
        zw: "商务合作",
        yw: "Business Cooperation"
      },
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})